package cn.highedu.controller;

import cn.highedu.entity.Reward;
import io.micrometer.core.instrument.DistributionSummary;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RewardController {
    private final DistributionSummary summary;

    public RewardController(MeterRegistry meter) {
        // 注册一个 DistributionSummary, 用于记录奖励的大小
        summary = DistributionSummary.builder("reward.summary")
                .baseUnit("units")
                .register(meter);
    }

    @PostMapping(value = "/rewards")
    public ResponseEntity<Void> create(@RequestBody Reward reward) {
        summary.record(reward.getAmount());
        return ResponseEntity.ok().build();
    }

}
